package com.datang.pet.api.musicController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-12 15:39
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.pojo.Music;
import com.datang.pet.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MusicController {
    @Autowired
    private MusicService musicService;

    /*
     * @author 顶风少年
     * @date 2019/6/12 15:43
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result Result
     * @notify 获取推荐音乐
     * version 1.0
     */
    @GetMapping("/getRecommendMusicList")
    public Result getRecommendMusicList() throws Exception {
        return Result.ok(musicService.getRecommendMusicList());
    }

    /*
     * @author 顶风少年
     * @date 2019/6/12 15:45
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param pageNumber
     * @result Result
     * @notify 获取音乐列表
     * version 1.0
     */
    @GetMapping("/getMusicList")
    public Result getMusicList(int pageNumber) throws Exception {
        return Result.ok(musicService.getMusicList(pageNumber));
    }


    /*
     * @author 顶风少年
     * @date 2019/6/12 15:46
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param music
     * @result Result
     * @notify 添加
     * version 1.0
     */
    @PostMapping("/addMusic")
    public Result addMusic(@RequestBody Music music) throws Exception {
        musicService.addMusic(music);
        return Result.ok("成功");
    }

    /*
     * @author 顶风少年
     * @date 2019/6/12 17:58
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param keyword
     * @param pageNumber
     * @result Result
     * @notify 搜索音乐
     * version 1.0
     */
    @GetMapping("/searchMusic")
    public Result searchMusic(String userId, String keyword) throws Exception {
        if (!StringUtils.isNUll(userId)) {
            throw new Exception("用户id为空");
        }
        return Result.ok(musicService.searchMusic(userId, keyword));
    }
}
